/*
* Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
*/

#include "vpc_pipe_yuvscaler.h"
#include "dvpp_cmdlist_num_define.h"

uint8_t judge_use_1prescale_1yuvscale(uint32_t in_width, uint32_t in_height, uint32_t out_width, uint32_t out_height)
{
    if ((out_height * NUM_8 >= in_height) && (out_width * NUM_8 >= in_width) &&
        (in_height * NUM_2 >= out_height) && (in_width * NUM_2 >= out_width)) {
        // [1/8, 2]
        return 1;
    }
    return 0;
}

uint8_t judge_use_2prescale_1yuvscale(uint32_t in_width, uint32_t in_height, uint32_t out_width, uint32_t out_height)
{
    if ((out_height * NUM_16 >= in_height) && (out_width * NUM_16 >= in_width) &&
        (in_height >= out_height) && (in_width >= out_width)) {
        // [1/16, 1]
        return 1;
    }
    return 0;
}

uint8_t judge_use_3prescale_1yuvscale(uint32_t in_width, uint32_t in_height, uint32_t out_width, uint32_t out_height)
{
    if ((out_height * NUM_32 >= in_height) && (out_width * NUM_32 >= in_width) &&
        (in_height >= out_height * NUM_2) && (in_width >= out_width * NUM_2)) {
        // [1/32, 1/2]
        return 1;
    }
    return 0;
}

uint8_t judge_use_1yuvscale(uint32_t in_width, uint32_t in_height, uint32_t out_width, uint32_t out_height)
{
    if (((out_height * NUM_4 >= in_height) && (out_width * NUM_4 >= in_width)) &&
        ((in_height * NUM_16 >= out_height) && (in_width * NUM_16 >= out_width))) {
        // [1/4, 16]
        return 1;
    }
    return 0;
}

const struct yuv_scaler_array* search_scaler_para(uint32_t para)
{
    return get_scaler_para(para);
}

uint8_t get_half_line_mode(uint64_t iv, uint32_t hsize)
{
    const uint64_t scalerRadio1Per6 = 0x2AAB;
    const uint64_t scalerRadio1Per2 = 0x8000;
    const uint32_t lineSize = 4096;

    if ((hsize <= (lineSize >> 1)) && (iv >= scalerRadio1Per6) && (iv <= scalerRadio1Per2)) {
        return 1;
    }

    return 0;
}